package com.wgy.day42Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Created by pc on 2021/1/11 20:58
 * Description: LearningJava
 */
/*Document对象功能*/
public class JsoupDemo3 {
    public static void main(String[] args) throws IOException {
        //1.获取student.xml的path
        // String path = JsoupDemo3.class.getClassLoader().getResource("student.xml").getPath();
        //2.获取document对象
        Document document = Jsoup.parse(new File("student.xml"), "utf-8");
        //3.获取元素对象
        //3.1获取所有student对象
        Elements elements = document.getElementsByTag("student");
        System.out.println(elements);
        System.out.println("=============");
        Elements  elements1 = document.getElementsByAttribute("id");
        System.out.println(elements1);
        System.out.println("=============");
        //3.2获取number属性值heima_0001的元素对象
        Elements elements2 = document.getElementsByAttributeValue("number", "heima_0001");
        System.out.println(elements2);
        System.out.println("=============");
        //3.3获取id属性值元素对象
        Element element = document.getElementById("1");
        System.out.println(element);



/*

        Element student1 = elements.get(0);
        Elements stu_name = student1.getElementsByTag("name");
        System.out.println(stu_name);
        System.out.println(stu_name.text());
*/


    }
}
